Warning: mkdir(): No space left on device in /var/www/tg-me/post.php on line 37

Warning: file_put_contents(aCache/aDaily/post/golangtests/--): Failed to open stream: No such file or directory in /var/www/tg-me/post.php on line 50
Go tests | Telegram Webview: golangtests/777 -
Telegram Group & Telegram Channel
🧠 Хитрая задача на Go (v1.22+) — алгоритмы, циклы и подвох в логике

📌 Задача: "Подряд идущие квадраты"

Дано: массив из N положительных целых чисел []int, например:


[]int{1, 4, 9, 16, 25, 36, 50, 64, 81}


Нужно найти максимальную длину подмассива, где все элементы — квадраты подряд идущих натуральных чисел.

Например, [4, 9, 16, 25] — это квадраты 2², 3², 4², 5² → длина = 4
[50, 64] — не подходят, так как 50 не является точным квадратом.

🎯 Формат функции:


func MaxConsecutiveSquares(nums []int) int


Пример:


input := []int{1, 4, 9, 16, 25, 36, 50, 64, 81}
fmt.Println(MaxConsecutiveSquares(input)) // 👉 6


🧩 Подвох:

- Часто пытаются сравнивать разности или применять хэшмапы — но это ошибка
- Нужно восстановить корни чисел (`sqrt`) и убедиться, что они натуральные и идут подряд
- Важно использовать math.Sqrt и быть осторожным с плавающей точкой (`float64`)
- Также важно не выходить за границы slice

💡 Подсказка:

```go
import "math"

func isSquare(n int) (int, bool) {
root := int(math.Sqrt(float64(n)))
return root, root*root == n
}
```

🛠 **Что проверяет задача:**

• Умение работать с нецелыми корнями
• Алгоритмы "двойного указателя" (две границы окна)
• Понимание строгой проверки на натуральные числа
• Внимание к float64-погрешности и типам



tg-me.com/golangtests/777
Create:
Last Update:

🧠 Хитрая задача на Go (v1.22+) — алгоритмы, циклы и подвох в логике

📌 Задача: "Подряд идущие квадраты"

Дано: массив из N положительных целых чисел []int, например:


[]int{1, 4, 9, 16, 25, 36, 50, 64, 81}


Нужно найти максимальную длину подмассива, где все элементы — квадраты подряд идущих натуральных чисел.

Например, [4, 9, 16, 25] — это квадраты 2², 3², 4², 5² → длина = 4
[50, 64] — не подходят, так как 50 не является точным квадратом.

🎯 Формат функции:


func MaxConsecutiveSquares(nums []int) int


Пример:


input := []int{1, 4, 9, 16, 25, 36, 50, 64, 81}
fmt.Println(MaxConsecutiveSquares(input)) // 👉 6


🧩 Подвох:

- Часто пытаются сравнивать разности или применять хэшмапы — но это ошибка
- Нужно восстановить корни чисел (`sqrt`) и убедиться, что они натуральные и идут подряд
- Важно использовать math.Sqrt и быть осторожным с плавающей точкой (`float64`)
- Также важно не выходить за границы slice

💡 Подсказка:

```go
import "math"

func isSquare(n int) (int, bool) {
root := int(math.Sqrt(float64(n)))
return root, root*root == n
}
```

🛠 **Что проверяет задача:**

• Умение работать с нецелыми корнями
• Алгоритмы "двойного указателя" (две границы окна)
• Понимание строгой проверки на натуральные числа
• Внимание к float64-погрешности и типам

BY Go tests


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/golangtests/777

View MORE
Open in Telegram


Go tests Telegram | DID YOU KNOW?

Date: |

Among the actives, Ascendas REIT sank 0.64 percent, while CapitaLand Integrated Commercial Trust plummeted 1.42 percent, City Developments plunged 1.12 percent, Dairy Farm International tumbled 0.86 percent, DBS Group skidded 0.68 percent, Genting Singapore retreated 0.67 percent, Hongkong Land climbed 1.30 percent, Mapletree Commercial Trust lost 0.47 percent, Mapletree Logistics Trust tanked 0.95 percent, Oversea-Chinese Banking Corporation dropped 0.61 percent, SATS rose 0.24 percent, SembCorp Industries shed 0.54 percent, Singapore Airlines surrendered 0.79 percent, Singapore Exchange slid 0.30 percent, Singapore Press Holdings declined 1.03 percent, Singapore Technologies Engineering dipped 0.26 percent, SingTel advanced 0.81 percent, United Overseas Bank fell 0.39 percent, Wilmar International eased 0.24 percent, Yangzijiang Shipbuilding jumped 1.42 percent and Keppel Corp, Thai Beverage, CapitaLand and Comfort DelGro were unchanged.

Start with a fresh view of investing strategy. The combination of risks and fads this quarter looks to be topping. That means the future is ready to move in.Likely, there will not be a wholesale shift. Company actions will aim to benefit from economic growth, inflationary pressures and a return of market-determined interest rates. In turn, all of that should drive the stock market and investment returns higher.

Go tests from ar


Telegram Go tests
FROM USA